#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define endl "\n"
using PII = pair<int, int>;
using TII = tuple<int, int, int>;
#define FOR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define FOR2(i, a, b, c) for (int i = (int)(a); i <= (int)(b); i += c)
#define FORD(i, b, a) for (int i = (int)(a); i >= (int)(b); i--)
#define FORD2(i, b, a, c) for (int i = (int)(a); i >= (int)(b); i -= c)
#define BSI basic_string<int>
#define BSPI basic_string<PII>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define VI vector<int>
#define VII vector<vector<int>>
#define VPII vector<PII>
#define lowbit(x) ((x)&(-x))
#define RE return;
#define RET return true;
#define REF return false;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;
#define pb push_back
#define fi first
#define se second
#define sz size()
constexpr int N = 1e5 + 10;
constexpr int mod = 998244353;

int __FAST_IO__ = [](){
    ios::sync_with_stdio(0), cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    return 0;
}();

VI bei[N];
int n,q;
int w[N];
set<int>s[N];

void solve() {
    cin>>n>>q;
    
    FOR(i,1,n)cin>>w[i],s[w[i]].insert(i);

    
    while(q--){
        int k,l,r;
        cin>>k>>l>>r;
        VPII ans;
        for(auto x:bei[k]){
            auto t=s[x].lower_bound(l);
            if(t!=s[x].end()&&*t<=r){
                ans.pb({*t,x});
            }
        }

        sort(ALL(ans));

        int lst=l;
        int res=0;

        for(auto& [x,y]:ans){
            res+=(x-lst)*k;
            lst=x;
            while(k%y==0)k/=y;
        }
        res+=(r-lst+1)*k;

        cout<<res<<endl;
    }

    FOR(i,1,n)s[w[i]].clear();

}

signed main() {
    int Task = 1;
 
    FOR(i,1,N-10){
        FOR2(j,i,N-10,i){
            bei[j].emplace_back(i);
        }
    }
 
    for (cin >> Task; Task; Task--) {
        solve();
    }
    return 0;
}